cmake_minimum_required(VERSION 3.5)
project(to_pointcloud)

if(NOT CMAKE_CXX_STANDARD)
   set(CMAKE_CXX_STANDARD 14)

endif()
SET(CMAKE_BUILD_TYPE "Release")

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
    add_compile_options(-Wall -Wextra -Wpedantic)
endif()

find_package(ament_cmake REQUIRED)
find_package(angles REQUIRED)
find_package(diagnostic_updater REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(message_filters REQUIRED)
find_package(PCL REQUIRED COMPONENTS common)
find_package(rclcpp REQUIRED)
find_package(rclcpp_components REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(tf2 REQUIRED)
find_package(tf2_ros REQUIRED)
find_package(lidar209_msgs REQUIRED)
find_package(pcl_conversions REQUIRED)

find_package(PkgConfig REQUIRED)
pkg_check_modules(YAML_CPP REQUIRED yaml-cpp)
find_path(YAML_CPP_INCLUDE_DIR
    NAMES yaml_cpp.h
    PATHS ${YAML_CPP_INCLUDE_DIRS})
find_library(YAML_CPP_LIBRARY
    NAMES YAML_CPP
    PATHS ${YAML_CPP_LIBRARY_DIRS})

link_directories(${YAML_CPP_LIBRARY_DIRS})

if(NOT ${YAML_CPP_VERSION} VERSION_LESS "0.5")
    add_definitions(-DHAVE_NEW_YAMLCPP)
endif()

include_directories(include ${PCL_COMMON_INCLUDE_DIRS} ${PCL_INCLUDE_DIRS} )

link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})


install(DIRECTORY config launch params
  DESTINATION share/${PROJECT_NAME})



add_library(lidar209_rawdata SHARED
    src/rawdata.cc
    src/calibration.cc)
ament_target_dependencies(lidar209_rawdata
    angles
    geometry_msgs
    rclcpp
    sensor_msgs
    tf2
    tf2_ros
    lidar209_msgs
    pcl_conversions
)

install(TARGETS lidar209_rawdata
    RUNTIME DESTINATION bin
    ARCHIVE DESTINATION lib
    LIBRARY DESTINATION lib)

add_library(lidar209_cloud_types SHARED
  src/pointcloudXYZIR.cpp
  src/organized_cloudXYZIR.cpp
)
ament_target_dependencies(lidar209_cloud_types
  rclcpp
  sensor_msgs
  tf2
  lidar209_msgs
)

install(TARGETS lidar209_cloud_types lidar209_rawdata
  RUNTIME DESTINATION bin
  ARCHIVE DESTINATION lib
  LIBRARY DESTINATION lib)



add_library(lidar209_convert SHARED
    src/convert.cc)
ament_target_dependencies(lidar209_convert
    diagnostic_updater
    Eigen3
    rclcpp
    rclcpp_components
    tf2
    lidar209_msgs
    pcl_conversions
)
target_link_libraries(lidar209_convert
    lidar209_cloud_types
    lidar209_rawdata
    ${YAML_CPP_LIBRARIES}
    ${Boost_SYSTEM_LIBRARY}
    ${PCL_LIBRARIES})

install(TARGETS lidar209_convert
    ARCHIVE DESTINATION lib
    LIBRARY DESTINATION lib
    RUNTIME DESTINATION bin
)


add_executable(to_pointcloud_node
   src/cloud_node.cc)
ament_target_dependencies(to_pointcloud_node
    rclcpp
)
target_link_libraries(to_pointcloud_node lidar209_convert)

rclcpp_components_register_nodes(lidar209_convert
    "lidar209_pointcloud::Convert")

install(TARGETS to_pointcloud_node
    DESTINATION lib/${PROJECT_NAME}
)

ament_package()

